﻿@{
    ViewBag.Title = "首页";
    Layout = "~/Views/Shared/_LayoutKoJSMobile.cshtml";
}
<style type="text/css">

    .nav { height:43px; position:relative; z-index:20;background:  #f8f8f8; 
    }
        .nav a { display:block; float:left; font-size:12px; color:#666;   width:112px; text-align:center;  height:40px; line-height:43px;
        }
            .nav .select, .nav a:hover {border-bottom:3px #48add9  solid; color:#323232;
            }

                
</style>
    <!-- middle-start -->
    <div class="aux-body">
        <!--<h1 class="itemtitle">My Resource</h1> -->
        <div class="aux-tabcontent">
            <div class="fx-grid">
                <div id="fx-scrollbar" style="width: 100%;">
                    <!-- style变化 height:650px; -->
                    <div id="fx-scrollbar-scrollable" style="width: 100%;">
                        <!-- style变化 -->
                        <div class="fx-grid-container fx-scrollbar-content" style="overflow: visible; width: 100%;">
                            <!-- style变化 -->
                            <div class="nav" id="nav">
                                @foreach (var item in ViewBag.OfficeSelection)
                                { 
                                    <a href="#" onclick="showbottom(this)" name="@item.GroupID">@item.GroupName</a>
                                }
	                            <a href="#" onclick="showbottom(this)" name ="public">公共</a>
                            </div>
                            <div>
                                <table id="gridTable1">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- middle-over -->


@section scripts {
    <script type="text/javascript">
        var IscheckPublic = '';
        $("#LayoutInspectionConsole").addClass("selected");
        $(document).ready(function () {
            $("#gridTable1").jqGrid({
            @*url: '/API'+'@Url.Action("GetRule", "InspectionRuleAPI")',
            datatype: 'json',*@
            url: '',
            datatype: 'local',
            rowNum: 100,
                colNames: ['RequestID', '模板ID', 'cChr_Department', 'cChr_Office', '模板名称', '模板描述', '创建人', '状态', '最后更新时间', 'cChr_MarkAsDelete', ''],
            colModel: [
                { index: "1", name: "RequestID", sorttype: "text", hidden: true },
                { index: "536870919", name: "cChr_TicketID", key: true, sorttype: "text", align: "center", width: 80 },
                { index: "536870913", name: "cChr_Department", sorttype: "text", hidden: true },
                { index: "536870914", name: "cChr_Office", sorttype: "text", hidden: true },
                { index: "536870915", name: "cChr_Name", sorttype: "text" },
                { index: "536870917", name: "cChr_Description", sorttype: "text" },
                { index: "536870916", name: "cChr_FullName", sorttype: "text", width: 50 },
                { index: "7", name: "Status", formatter: Generateimg, width: 60 ,hidden:true},
                { index: "536870920", name: "ModifiedDate", sorttype: "date", formatter: DateModify, width: 100 },
                { index: "536870918", name: "cChr_MarkAsDelete", sorttype: "text", hidden: true },
                { index: "Operation", name: "Operation", sorttype: "text", sorttype: "text", formatter: GenerateButton, width: 50 }
            ],
            //caption: "计划巡检控制台",
            viewrecords: true,
            jsonReader: {
                repeatitems: false,
                id: "RequestID"
            },
            mtype: "GET",
                sortable: true,
            autowidth: true,
            sortname: 'ModifiedDate',
            sortorder: 'desc',
            postData: {
                Permission: 'public',
            }, //发送数据
            prmNames: {
                id: 'Type'
            },
            scroll: true,
            scrollOffset: 0,
            height: "430",
            width: "980",
            viewrecords: true,
            gridview: true,
                beforeSelectRow: function (rowid, status, e, rowObject) {
                    return false;
                },

            onSelectRow: function () {
            },
            ondblClickRow: function (rowid, iRow, iCol, e) {
                window.location.href = "/InspectionTicket/Modify?TicketID=" + rowid + "&CheckPublic=" + IscheckPublic;
                //window.open("../InspectionTicket/Modify?TicketID=" + rowid);
            },
            gridComplete: function () {

            },
            loadComplete: function () {

            }
        });

            $($("#nav").children()[0]).addClass("select");
            LoadHosts($(".select").attr("name"));
        });

        function showbottom(obj) {
            IscheckPublic=$(obj).attr("name");
            $("#nav").children().removeClass("select");
            $(obj).addClass("select");
            LoadHosts($(obj).attr("name"));
        }


        function LoadHosts(groupid) {
            var data = {};
            if ('@ViewBag.Excute'.valueOf() == 0) {
                jQuery("#gridTable1").jqGrid("setGridParam", {
                    url: "/API/InspectionTicketAPI/GetAll?cChr_office=" + groupid, //设置表格的url
                    datatype: "json", //设置数据类型
                    postData: { strJson: data }
                }).hideCol("Operation").setGridWidth(898).trigger("reloadGrid");
            }
            else if ('@ViewBag.Excute'.valueOf() == 1) {
                jQuery("#gridTable1").jqGrid("setGridParam", {
                    url: "/API/InspectionTicketAPI/GetAll?cChr_office=" + groupid, //设置表格的url
                    datatype: "json", //设置数据类型
                    postData: { strJson: data }
                }).trigger("reloadGrid");
            }
   }

        function Generateimg(cellvalue, options, rowObject) {
            if (rowObject.Status == 0) {
                returnStrimg = '<div id=\'div1' + rowObject.RequestID + '\' style=" width: 55px;height: 25px;border-radius: 20px;position: relative;"  class="open1"><div  id=\'div2' + rowObject.RequestID + '\'  style="width: 25px;height: 20px;border-radius: 16px;position: absolute;background: white;box-shadow: 0px 2px 4px rgba(0,0,0,0.4);" class="open2" onclick="openorclose(\'div1' + rowObject.RequestID + '\',\'div2' + rowObject.RequestID + '\',\'' + rowObject.RequestID + '\')"></div></div>';
            }
            else
                returnStrimg = '<div id=\'div1' + rowObject.RequestID + '\' style=" width: 55px;height: 25px;border-radius: 20px;position: relative;"  class="close1"><div  id=\'div2' + rowObject.RequestID + '\'  style="width: 25px;height: 20px;border-radius: 16px;position: absolute;background: white;box-shadow: 0px 2px 4px rgba(0,0,0,0.4);" class="close2" onclick="openorclose(\'div1' + rowObject.RequestID + '\',\'div2' + rowObject.RequestID + '\',\'' + rowObject.RequestID + '\')"></div></div>';
            return '<center>' + returnStrimg + '</center>';
   }

    function GenerateButton(cellvalue, options, rowObject) {
        returnStr = '<input type="button" class="generate" style=" width:33px;" title="生成"  onclick="GenerateTask(\'' + rowObject.RequestID + '\')" value=""></input>';
        return '<center>' + returnStr + '</center>';
    }

        function DateModify(cellvalue, options, rowObject) {
            return rowObject.ModifiedDate.replace("T", " ").replace("+08:00", "");
        }

        var IsStatus = 0;
        function openorclose(di1, di2, RequestIDs) {
            var data = {};
            var div2 = document.getElementById(di2);
            var div1 = document.getElementById(di1);
            div1.className = (div1.className == "close1") ? "open1" : "close1";
            div2.className = (div2.className == "close2") ? "open2" : "close2";
            if (div1.className == "open1") {
                IsStatus = 0;
            }
            else {
                IsStatus = 4;
            }
            data['Status'] = IsStatus;
            $.ajax("/API/InspectionTicketAPI?id=" + RequestIDs, {
                data: JSON.stringify(data),
                type: "PUT", contentType: "application/json",
                async: false,
                success: function (data) {

                }
            });
    }

        function TaskFrame() {
        //window.open("../Home/MyTask");
        window.location.href = "/Home/MyTask";
    }
        function GenerateTask(RequestID) {
            $("#aux-foreground").showLoading();
            var IsTaskFrame = "TaskFrame";
            var data = {};
            data['RequestID'] = RequestID;
            $.ajax("/API/InspectionTaskAPI/", {
                data: JSON.stringify(data),
                type: "POST", contentType: "application/json",
                success: function (data) {
                    $("#aux-foreground").hideLoading();
                    if (data.message.indexOf('Fail') >= 0) {
                        alert("请检查模板是否包含指标检查项");
                    }
                    else
                        window.location.href = "/InspectionTask/IndexMobile?GTicketID=" + data.GTicketID + "&PageName=" + IsTaskFrame;
                }
            });
        }

    </script>
}